package com.sice1.www;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class CardDemo {
    public static final String[]suits={"♥","♠","♣","♦"};

    public List<Card> buyCard(){
        List<Card>cardList=new ArrayList<>();
        for (int i = 1; i <=13 ; i++) {
            for (int j = 0; j <4 ; j++) {
                int rank=i;
                String suit=suits[j];
                Card card=new Card(suit,rank);
                cardList.add(card);
            }
        }
        return cardList;
    }



    //洗牌
    public void shuffle(List<Card>cardList){
        Random r=new Random();

        for (int i = 0; i <cardList.size(); i++) {
            int index=r.nextInt(cardList.size());
            swap(cardList,index,i);
        }
    }
    //随机数交换
    public static void swap(List<Card>cardList,int index,int i ){
        Card card=cardList.get(index);
        cardList.set(index,cardList.get(i));
        cardList.set(i,card);
    }

    //玩牌
    public List<List<Card>> paly(List<Card>cardList){
        List<Card>hand0=new ArrayList<>();
        List<Card>hand1=new ArrayList<>();
        List<Card>hand2=new ArrayList<>();
        List<List<Card>>hand=new ArrayList<>();
        hand.add(hand0);
        hand.add(hand1);
        hand.add(hand2);
        for (int i = 0; i <5 ; i++) {
            hand0.add(cardList.remove(0));
            hand1.add(cardList.remove(0));
            hand2.add(cardList.remove(0));
        }
        return hand;
    }
}
